<?php
class Private_m extends MY_Model{
	
	function __construct(){
		parent::__construct();
		$this->_table = 'business_private';
	}
	
	public function get_many_by($params = array(),$page_size){
		//date_default_timezone_set('Asia/Ho_Chi_Minh');
		$this->get_many_by_query($params);
		$total_row = $this->db->count_all_results($this->_table);
		
		if ( ! empty($params['limit']))
		{
			 $this->db->limit($page_size,$params['limit'] * $page_size);			
		}
		else
			$this->db->limit($page_size);
		$this->get_many_by_query($params);
		$projects = parent::get_all();
		$result = new stdClass();
		$result->projects = $projects;
		$result->total_row = $total_row;
		return $result;
	}
	
	private function get_many_by_query($params = array(),$page_size = 10,$join_table = TRUE){
		$this->_table = 'business_private p';
		$this->db->select('p.*,u.display_name');
		$this->db->join('ser_users u','u.id = p.user_id');
		if(!empty($params['user_id'])){
			$this->db->where('p.user_id ',$params['user_id']);
		}
		//cong viec cua phong ban
		if(!empty($params['room'])){
			$this->db->where('p.room_id',$params['room']);
		}
		$this->db->order_by('p.status');
		$this->db->order_by('p.date_start','desc');
		
	}
	
	public function insert($data){
		$data['created'] = strtotime(date("Y-m-d"));
		$data['user_id'] = $this->current_user->id;
		$data['month'] = date("m");
		$data['year'] = date("Y");
		$data['date_start'] = strtotime($data['date_start']);
		$data['date_end'] = strtotime($data['date_end']);
		$data['status'] = 0;
		return parent::insert($data);
	}
}